/****************************************************************                        
 * Project:      Wolf Custom Report Engine                                       
 * JDK version:  5.0                              
 * Namespace:    wolf.opensource.lcre.core                              
 * Author:       Wolfyan
 * Email:        wolf.opensource@gmail.com           
 * Create Date:  2009-1-1
 * 
 * Modified By:                                             
 * Modified Date:                                    
 *    
 * 
 * Version:      1.0.0.0                   
 *****************************************************************/
package wolf.opensource.lcre.core;

import java.util.HashMap;
import java.util.StringTokenizer;

import wolf.opensource.lcre.util.StringHelper;

/**
 * The Class Style.
 */
public class Style extends HashMap<String, String>{
	
	private static final long serialVersionUID = -3599428243346487175L;
	
	int id;
	String height;
	String width;
	String textAlign;
	String verticalAlign;
	String fontColor;
	String fontWeight;
	String fontSize;
	String backgroundColor;
	String borderWeight;
	String borderStyle;
	String borderColor;
	
	/**
	 * Instantiates a new style.
	 * 
	 * @param id the id
	 */
	public Style(int id) {
		this.id = id;
	}

	public String getHeight() {
		return getValue("height");
	}

	public String getWidth() {
		return getValue("width");
	}

	public String getTextAlign() {
		return getValue("text-align");
	}
	
	public String getVerticalAlign() {
		return getValue("vertical-align");
	}

	public String getFontColor() {
		return getValue("font-color");
	}

	public String getFontWeight() {
		return getValue("font-weight");
	}
	
	public String getFontSize() {
		return getValue("font-size");
	}

	public String getBackgroundColor() {
		return getValue("background-color");
	}

	public String getHtmlStyle(){
		StringBuffer sb = new StringBuffer();
		if (StringHelper.isNotEmpty(this.getWidth()))
			sb.append("width:").append(this.getWidth()).append(";");
		if (StringHelper.isNotEmpty(this.getHeight()))
			sb.append("height:").append(this.getHeight()).append(";");
		if (StringHelper.isNotEmpty(this.getTextAlign()))
			sb.append("text-align:").append(this.getTextAlign()).append(";");
		if (StringHelper.isNotEmpty(this.getVerticalAlign()))
			sb.append("vertical-align:").append(this.getVerticalAlign()).append(";");
		if (StringHelper.isNotEmpty(this.getFontColor()))
			sb.append("font-color:").append(this.getFontColor()).append(";");
		if (StringHelper.isNotEmpty(this.getFontWeight()))
			sb.append("font-weight:").append(this.getFontWeight()).append(";");
		if (StringHelper.isNotEmpty(this.getFontSize()))
			sb.append("font-size:").append(this.getFontSize()).append(";");
		if (StringHelper.isNotEmpty(this.getBackgroundColor()))
			sb.append("background-color:").append(this.getBackgroundColor()).append(";");
		return sb.toString();
	}
		
	private String getValue(String key){
		String value = "";
		if ( this.containsKey(key)) {
			value = this.get(key).toString();
		}
		return value;
	}
	
	public String getCellStyle() {
		return null;
	}
	
	public static Style parse(String input) {
		Style style = new Style(20);
		StringTokenizer st = new StringTokenizer(input,";",false);
		
        while( st.hasMoreElements() ){
        	String sub = st.nextToken();
        	
        	System.out.println( sub.trim() );
        	
        	StringTokenizer stSub = new StringTokenizer(sub, ":", false);
    		String key = "";
    		String value = "";
    		
    		if ( stSub.hasMoreElements()) {
    			key = stSub.nextToken();
        		if ( stSub.hasMoreElements()) {
        			value = stSub.nextToken();
        			if (StringHelper.isNotEmpty(value)) {
        				style.put(key, value);
            		}
        		}
    		}
        }

		return style;
	}
}
